import React, { Component } from 'react';

import axios from 'axios'
class Myclschild2 extends Component {
    render() {
        return (
            <div>
                子组件2
            </div>
        );
    };
    state = {
        source: axios.CancelToken.source()  // 创建一个axios请求的对象
    }
    componentDidMount() {
        console.log('子组件2');
        // 发起请求
        axios.post('https://api.i-lynn.cn/college', {
            page: 1
        }, {
            cancelToken: this.state.source.token // 设置取消请求的标记
        }).then(res => {
            console.log(res);
        }).catch(e => { })
    };
    componentWillUnmount() {
        // 取消请求
        this.state.source.cancel('Operation canceled by the user.');
    }
}

export default Myclschild2;
